﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Validity.Test.Constraints.ComparisonConstraints
{
  [TestClass]
  public class IsLessThanConstraintTest
    : ConstraintTestBase<ObjectStub>
  {
    public class Validator
      : ValidatorBase<ObjectStub>
    {
      public Validator()
      {
        DefineRulesFor(ctx => ctx.MyDecimalProperty1).IsLessThan(0);
        DefineRulesFor(ctx => ctx.MyDecimalProperty2).IsLessThan(() => 0);
        DefineRulesFor(ctx => ctx.MyDecimalProperty3).IsLessThan(obj => 0);

        DefineRulesFor(ctx => ctx.MyNullableDecimalProperty1).IsLessThan(0);
        DefineRulesFor(ctx => ctx.MyNullableDecimalProperty2).IsLessThan(() => 0);
        DefineRulesFor(ctx => ctx.MyNullableDecimalProperty3).IsLessThan(obj => 0);
      }
    }

    public IsLessThanConstraintTest() : base(new Validator(), 6) { }

    [TestMethod]
    public void TestConstraintVerified()
    {
      ValidateConstraintVerfied(CreateContext(Decimal.MinValue));
      ValidateConstraintVerfied(CreateContext(Decimal.MinusOne));
    }

    [TestMethod]
    public void TestConstraintViolated()
    {
      const String ruleViolation = "Must be less than '0'";

      ValidateConstraintViolated(CreateContext(Decimal.Zero), ruleViolation);
      ValidateConstraintViolated(CreateContext(Decimal.One), ruleViolation);
      ValidateConstraintViolated(CreateContext(Decimal.MaxValue), ruleViolation);
    }

    public ObjectStub CreateContext(Decimal value)
    {
      var result = new ObjectStub();

      result.MyDecimalProperty1 = value;
      result.MyDecimalProperty2 = value;
      result.MyDecimalProperty3 = value;

      result.MyNullableDecimalProperty1 = value;
      result.MyNullableDecimalProperty2 = value;
      result.MyNullableDecimalProperty3 = value;

      return result;
    }
  }
}
